package cluedo.gui;


import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;


import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextPane;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import cluedo.Card;
import cluedo.Character;
import cluedo.Player;
import cluedo.Room;
import cluedo.Weapon;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Image;
import java.util.HashMap;
import java.util.Map;

import static cluedo.Player.log;


public class WestPanel extends JPanel implements DragGestureListener, ActionListener,ChangeListener,MouseMotionListener{

	private static final long serialVersionUID = -5186721214275551731L;
	
	/**
	 * Variabile per gestire la dimensione delle carte armi
	 */
	private final int SCALEWEAP=120;
	
	/**
	 * Variabile per gestire la dimensione delle carte personaggio
	 */
	private final int SCALECH=120;
	
	/**
	 * Variabile per gestire la dimensione delle carte stanze
	 */
	private final int SCALEROOM=120;
	
	/**
	 * Variabile per gestire spazio tra le carte armi
	 */
	private final int SPACEBETWWEAP=10;
	
	/**
	 * Variabile per gestire spazio tra le carte stanze
	 */
	private final int SPACEBETWROOM=10;
	
	/**
	 * Variabile per gestire spazio tra le carte personaggio
	 */
	private final int SPACEBETWCH=10;
	
	/**
	 * Spazio per separare le sezioni esci, JTabbedPane e info
	 */
	private final int SPACEBETWSECT=20;
	
	/**
	 * Il player associato alla MainWindow che contiene il WestPanel
	 */
	private Player myPlayer=null;
	
	/**
	 * Contiene tutte le carte sul tavolo di gioco; 
	 * la chiave e' il nome della carta
	 * il valore e' l'oggetto carta corrispondente
	 */
	
	private HashMap<String,Card> allCard;
	
	/**
	 * Mappa l'etichetta che raffigura una carta con la carta corrispondente 
	 * la chiave e' la JLabel che contiene l'immagine della carta 
	 * il valore e' la carta
	 */
	
	private HashMap<JLabel,Card> allLabel;
	
	/**
	 * Pannello che contiene le carte divise per tab in base alla tipologia (personaggio,arma,stanza)
	 */
	private JTabbedPane tabbedPane;
		
	/**
	 * Riferimento alla MainWindow che contiene il WestPanel
	 */
	private MainWindow wind;
	
	/**
	 * bottone esci 
	 */
    private JButton btnQuit;

	/**
	 * Area delle informazioni
	 */
    private JTextPane info;
    
	/**
	 * Crea il WestPanel
	 */
	public WestPanel(Player myPlayer,MainWindow wind) {
		
		log.printLog("E' iniziata la creazione del pannello West");
		
		this.wind=wind;
		this.myPlayer=myPlayer;
		
		allCard=new HashMap<String,Card>();
		allLabel=new HashMap<JLabel,Card>();
		
		this.setBackground(Color.BLACK);
		
		this.setLayout(new BorderLayout());
		
		JPanel downPane = new JPanel();
		
		downPane.setBackground(Color.BLACK);
		
		downPane.setLayout(new BoxLayout(downPane, BoxLayout.Y_AXIS));
		
		
		JPanel userPane = new JPanel();
		
		userPane.setBackground(Color.BLACK);
		
		userPane.setLayout(new BoxLayout(userPane, BoxLayout.X_AXIS));
		
		Cursor handCurs = new Cursor(Cursor.HAND_CURSOR);
		
		Image exitImg = new ImageIcon(MainWindow.class.getResource("/img/exit.png")).getImage();
		ImageIcon exitIcon= new ImageIcon(exitImg.getScaledInstance(-1, 35, Image.SCALE_SMOOTH));
		btnQuit = new JButton();
		btnQuit.setIcon(exitIcon);
		btnQuit.setBorder(null);
		btnQuit.setContentAreaFilled(false);
		btnQuit.setBorderPainted(false);
		btnQuit.setToolTipText("Esci");
		btnQuit.setActionCommand("Quit");
		btnQuit.addActionListener(this);
		btnQuit.setCursor(handCurs);
		
		userPane.add(btnQuit);
		
		userPane.add(Box.createRigidArea(new Dimension(5,0)));
		
		Image helpImg = new ImageIcon(MainWindow.class.getResource("/img/help.png")).getImage();
		ImageIcon helpIcon= new ImageIcon(helpImg.getScaledInstance(-1, 50, Image.SCALE_SMOOTH));
		JButton btnHelp = new JButton();
		btnHelp.setIcon(helpIcon);
		btnHelp.setBorder(null);
		btnHelp.setContentAreaFilled(false);
		btnHelp.setBorderPainted(false);
		btnHelp.setToolTipText("Aiuto");
		btnHelp.setActionCommand("Help");
		btnHelp.addActionListener(wind);
		btnHelp.setCursor(handCurs);
		
		userPane.add(btnHelp);
		
		userPane.add(Box.createRigidArea(new Dimension(5,0)));
		
		JLabel characterName = new JLabel(myPlayer.getPawn().getName());
		characterName.setForeground(myPlayer.getPlayerColor(myPlayer.getNickname()));
		characterName.setFont(new Font("Verdana", Font.PLAIN, 18));
		
		userPane.add(characterName);
		
		userPane.add(Box.createRigidArea(new Dimension(5,0)));
		
		tabbedPane = new JTabbedPane();
		
		tabbedPane.setFocusable(false); // rimuove linee di focus che si creano quando si clicca su un tab
		
		tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
		
		tabbedPane.setBackground(Color.BLACK);
				
		tabbedPane.addMouseMotionListener(this);
		
		JPanel characterPane=new JPanel();
		
		characterPane.setBackground(Color.BLACK);
		
		characterPane.setLayout(new BoxLayout(characterPane, BoxLayout.X_AXIS));
				
		JPanel allCharacterPane =new JPanel();
		
		allCharacterPane.setBackground(Color.BLACK);
		
		allCharacterPane.setBorder(BorderFactory.createLineBorder(Color.GRAY));
		
		JPanel characterPaneLeft=new JPanel();
		
		characterPaneLeft.setLayout(new BoxLayout(characterPaneLeft, BoxLayout.Y_AXIS));
		
		characterPaneLeft.setBackground(Color.BLACK);

		characterPaneLeft.add(Box.createRigidArea(new Dimension(0,SPACEBETWCH)));
		
		Character plum=new Character("Professor Plum");
		JLabel plumImg = new JLabel();
		plumImg.setIcon(plum.getScaledImage(SCALECH));
		plumImg.setToolTipText(plum.getName());
		allCard.put("Professor Plum", plum);
		allLabel.put(plumImg, plum);
		DragSource plumDS = new DragSource();
	    plumDS.createDefaultDragGestureRecognizer(plumImg, DnDConstants.ACTION_COPY, this);
		characterPaneLeft.add(plumImg);
		
		characterPaneLeft.add(Box.createRigidArea(new Dimension(0,SPACEBETWCH)));
		
		Character peacock=new Character("Mrs Peacock");
		JLabel peacockImg = new JLabel();
		peacockImg.setIcon(peacock.getScaledImage(SCALECH));
		peacockImg.setToolTipText(peacock.getName());
		allCard.put("Mrs Peacock", peacock);
		allLabel.put(peacockImg, peacock);
		DragSource peacockDS = new DragSource();
	    peacockDS.createDefaultDragGestureRecognizer(peacockImg, DnDConstants.ACTION_COPY, this);
		characterPaneLeft.add(peacockImg);
		
		characterPaneLeft.add(Box.createRigidArea(new Dimension(0,SPACEBETWCH)));

		Character mustard=new Character("Colonel Mustard");
		JLabel mustardImg = new JLabel();
		mustardImg.setIcon(mustard.getScaledImage(SCALECH));
		mustardImg.setToolTipText(mustard.getName());
		allCard.put("Colonel Mustard", mustard);
		allLabel.put(mustardImg, mustard);
		DragSource mustardDS = new DragSource();
	    mustardDS.createDefaultDragGestureRecognizer(mustardImg, DnDConstants.ACTION_COPY, this);
		characterPaneLeft.add(mustardImg);
		
		characterPaneLeft.add(Box.createRigidArea(new Dimension(0,10)));
				
		JPanel characterPaneRight=new JPanel();
		
		characterPaneRight.setLayout(new BoxLayout(characterPaneRight, BoxLayout.Y_AXIS));
		
		characterPaneRight.setBackground(Color.BLACK);
		
		characterPaneRight.add(Box.createRigidArea(new Dimension(0,SPACEBETWCH)));
		
		Character scarlett=new Character("Miss Scarlett");
		JLabel scarlettImg = new JLabel();
		scarlettImg.setIcon(scarlett.getScaledImage(SCALECH));
		scarlettImg.setToolTipText(scarlett.getName());
		allCard.put("Miss Scarlett", scarlett);
		allLabel.put(scarlettImg, scarlett);
		DragSource scarlettDS = new DragSource();
	    scarlettDS.createDefaultDragGestureRecognizer(scarlettImg, DnDConstants.ACTION_COPY, this);
		characterPaneRight.add(scarlettImg);
		
		characterPaneRight.add(Box.createRigidArea(new Dimension(0,SPACEBETWCH)));
		
		Character green=new Character("Rev. Green");
		JLabel greenImg = new JLabel();
		greenImg.setIcon(green.getScaledImage(SCALECH));
		greenImg.setToolTipText(green.getName());
		allCard.put("Rev. Green", green);
		allLabel.put(greenImg, green);
		DragSource greenDS = new DragSource();
	    greenDS.createDefaultDragGestureRecognizer(greenImg, DnDConstants.ACTION_COPY, this);
	    characterPaneRight.add(greenImg);
		
	    characterPaneRight.add(Box.createRigidArea(new Dimension(0,SPACEBETWCH)));

	    Character white=new Character("Mrs White");
		JLabel whiteImg = new JLabel();
		whiteImg.setIcon(white.getScaledImage(SCALECH));
		whiteImg.setToolTipText(white.getName());
		allCard.put("Mrs White", white);
		allLabel.put(whiteImg, white);
		DragSource whiteDS = new DragSource();
	    whiteDS.createDefaultDragGestureRecognizer(whiteImg, DnDConstants.ACTION_COPY, this);
	    characterPaneRight.add(whiteImg);
		
	    characterPaneRight.add(Box.createRigidArea(new Dimension(0,10)));
	    
	    characterPane.add(characterPaneLeft);
	    characterPane.add(Box.createRigidArea(new Dimension(SPACEBETWCH,0)));
	    characterPane.add(characterPaneRight);
	    
	    allCharacterPane.add(characterPane);
	    
		tabbedPane.addTab("PERSONAGGI",allCharacterPane);
		
		allCharacterPane.setName("PERSONAGGI");		
		
		JPanel weaponPane=new JPanel();
		
		weaponPane.setLayout(new BoxLayout(weaponPane, BoxLayout.X_AXIS));

		weaponPane.setBackground(Color.BLACK);
		
		
		JPanel weaponPaneLeft=new JPanel();
		
		weaponPaneLeft.setLayout(new BoxLayout(weaponPaneLeft, BoxLayout.Y_AXIS));

		weaponPaneLeft.setBackground(Color.BLACK);
						
		Weapon candlestick=new Weapon("candlestick");
		JLabel candlestickImg = new JLabel();
		candlestickImg.setIcon(candlestick.getScaledImage(SCALEWEAP));
		candlestickImg.setToolTipText(candlestick.getName());
		allCard.put("candlestick", candlestick);
		allLabel.put(candlestickImg, candlestick);
		DragSource candlestickDS = new DragSource();
	    candlestickDS.createDefaultDragGestureRecognizer(candlestickImg, DnDConstants.ACTION_COPY, this);
		candlestickImg.setBorder(BorderFactory.createLineBorder(Color.black));
		weaponPaneLeft.add(candlestickImg);
		
		
		weaponPaneLeft.add(Box.createRigidArea(new Dimension(0, SPACEBETWWEAP)));  
		
		Weapon knife=new Weapon("knife");
		JLabel knifeImg = new JLabel();
		knifeImg.setIcon(knife.getScaledImage(SCALEWEAP));
		knifeImg.setToolTipText(knife.getName());
		allCard.put("knife", knife);
		allLabel.put(knifeImg, knife);
		DragSource knifeDS = new DragSource();
		knifeDS.createDefaultDragGestureRecognizer(knifeImg, DnDConstants.ACTION_COPY, this);
		knifeImg.setBorder(BorderFactory.createLineBorder(Color.black));
		weaponPaneLeft.add(knifeImg);
		
		weaponPaneLeft.add(Box.createRigidArea(new Dimension(0, SPACEBETWWEAP)));  

		
		Weapon leadPipe=new Weapon("leadPipe");
		JLabel leadPipeImg = new JLabel();
		leadPipeImg.setIcon(leadPipe.getScaledImage(SCALEWEAP));
		leadPipeImg.setToolTipText(leadPipe.getName());
		allCard.put("leadPipe", leadPipe);
		allLabel.put(leadPipeImg, leadPipe);
		DragSource leadPipeDS = new DragSource();
		leadPipeDS.createDefaultDragGestureRecognizer(leadPipeImg, DnDConstants.ACTION_COPY, this);
		leadPipeImg.setBorder(BorderFactory.createLineBorder(Color.black));
		weaponPaneLeft.add(leadPipeImg);
		

		JPanel weaponPaneRight=new JPanel();
		
		weaponPaneRight.setLayout(new BoxLayout(weaponPaneRight, BoxLayout.Y_AXIS));
		weaponPaneRight.setBackground(Color.BLACK);
		
		Weapon revolver=new Weapon("revolver");
		JLabel revolverImg = new JLabel();
		revolverImg.setIcon(revolver.getScaledImage(SCALEWEAP));
		revolverImg.setToolTipText(revolver.getName());
		allCard.put("revolver", revolver);
		allLabel.put(revolverImg, revolver);
		DragSource revolverDS = new DragSource();
		revolverDS.createDefaultDragGestureRecognizer(revolverImg, DnDConstants.ACTION_COPY, this);
		revolverImg.setBorder(BorderFactory.createLineBorder(Color.black));
		weaponPaneRight.add(revolverImg);
		
		weaponPaneRight.add(Box.createRigidArea(new Dimension(0, SPACEBETWWEAP)));  

		
		Weapon rope=new Weapon("rope");
		JLabel ropeImg = new JLabel();
		ropeImg.setIcon(rope.getScaledImage(SCALEWEAP));
		ropeImg.setToolTipText(rope.getName());
		allCard.put("rope", rope);
		allLabel.put(ropeImg, rope);
		DragSource ropeDS = new DragSource();
		ropeDS.createDefaultDragGestureRecognizer(ropeImg, DnDConstants.ACTION_COPY, this);
		ropeImg.setBorder(BorderFactory.createLineBorder(Color.black));
		weaponPaneRight.add(ropeImg);
		
		weaponPaneRight.add(Box.createRigidArea(new Dimension(0, SPACEBETWWEAP)));  

		
		Weapon wrench=new Weapon("wrench");
		JLabel wrenchImg = new JLabel();
		wrenchImg.setIcon(wrench.getScaledImage(SCALEWEAP));
		wrenchImg.setToolTipText(wrench.getName());
		allCard.put("wrench", wrench);
		allLabel.put(wrenchImg, wrench);
		DragSource wrenchDS = new DragSource();
		wrenchDS.createDefaultDragGestureRecognizer(wrenchImg, DnDConstants.ACTION_COPY, this);
		wrenchImg.setBorder(BorderFactory.createLineBorder(Color.black));
		weaponPaneRight.add(wrenchImg);
		
		JPanel allWeaponPane =new JPanel();
		
		allWeaponPane.setBackground(Color.BLACK);

		allWeaponPane.setBorder(BorderFactory.createLineBorder(Color.GRAY));

		weaponPane.add(weaponPaneLeft);
		weaponPane.add(Box.createRigidArea(new Dimension(SPACEBETWCH,0)));
		weaponPane.add(weaponPaneRight);
		
		allWeaponPane.add(weaponPane);
		
		tabbedPane.addTab("ARMI",allWeaponPane);
		
		allWeaponPane.setName("ARMI");
				
		JPanel roomPane = new JPanel();  
		
		roomPane.setLayout(new BoxLayout(roomPane, BoxLayout.X_AXIS));
				
		roomPane.setBackground(Color.BLACK);
		
		JPanel roomPaneLeft=new JPanel();
		
	    roomPaneLeft.setLayout(new BoxLayout(roomPaneLeft, BoxLayout.Y_AXIS));
		roomPaneLeft.setBackground(Color.BLACK);
						
		Room ballRoom=new Room("BallRoom");
		JLabel ballRoomImg = new JLabel();
		ballRoomImg.setIcon(ballRoom.getScaledImage(SCALEROOM));
		ballRoomImg.setToolTipText(ballRoom.getName());
		allCard.put("BallRoom", ballRoom);
		allLabel.put(ballRoomImg, ballRoom);
		DragSource ballRoomDS = new DragSource();
		ballRoomDS.createDefaultDragGestureRecognizer(ballRoomImg, DnDConstants.ACTION_COPY, this);
		ballRoomImg.setBorder(BorderFactory.createLineBorder(Color.black));
		roomPaneLeft.add(ballRoomImg);
		
		roomPaneLeft.add(Box.createRigidArea(new Dimension(0, SPACEBETWROOM)));  
		
		Room billiardRoom=new Room("Billiard Room");
		JLabel billiardRoomImg = new JLabel();
		billiardRoomImg.setIcon(billiardRoom.getScaledImage(SCALEROOM));
		billiardRoomImg.setToolTipText(billiardRoom.getName());
		allCard.put("Billiard Room", billiardRoom);
		allLabel.put(billiardRoomImg, billiardRoom);
		DragSource billiardRoomDS = new DragSource();
		billiardRoomDS.createDefaultDragGestureRecognizer(billiardRoomImg, DnDConstants.ACTION_COPY, this);
		billiardRoomImg.setBorder(BorderFactory.createLineBorder(Color.black));
		roomPaneLeft.add(billiardRoomImg);
		
		roomPaneLeft.add(Box.createRigidArea(new Dimension(0, SPACEBETWROOM)));  
		
		Room kitchen=new Room("Kitchen");
		JLabel kitchenImg = new JLabel();
		kitchenImg.setIcon(kitchen.getScaledImage(SCALEROOM));
		kitchenImg.setToolTipText(kitchen.getName());
		allCard.put("Kitchen", kitchen);
		allLabel.put(kitchenImg, kitchen);
		DragSource kitchenDS = new DragSource();
		kitchenDS.createDefaultDragGestureRecognizer(kitchenImg, DnDConstants.ACTION_COPY, this);
		kitchenImg.setBorder(BorderFactory.createLineBorder(Color.black));
		roomPaneLeft.add(kitchenImg);
		
		roomPane.add(roomPaneLeft);

		JPanel roomPaneCenter=new JPanel();
		
		roomPaneCenter.setLayout(new BoxLayout(roomPaneCenter, BoxLayout.Y_AXIS));
		roomPaneCenter.setBackground(Color.BLACK);
		
		Room diningRoom=new Room("Dining Room");
		JLabel diningRoomImg = new JLabel();
		diningRoomImg.setIcon(diningRoom.getScaledImage(SCALEROOM));
		diningRoomImg.setToolTipText(diningRoom.getName());
		allCard.put("Dining Room", diningRoom);
		allLabel.put(diningRoomImg, diningRoom);
		DragSource diningRoomDS = new DragSource();
		diningRoomDS.createDefaultDragGestureRecognizer(diningRoomImg, DnDConstants.ACTION_COPY, this);
		diningRoomImg.setBorder(BorderFactory.createLineBorder(Color.black));
		roomPaneCenter.add(diningRoomImg);
		
		roomPaneCenter.add(Box.createRigidArea(new Dimension(0, SPACEBETWROOM)));  

		
		Room lounge=new Room("Lounge");
		JLabel loungeImg = new JLabel();
		loungeImg.setIcon(lounge.getScaledImage(SCALEROOM));
		loungeImg.setToolTipText(lounge.getName());
		allCard.put("Lounge", lounge);
		allLabel.put(loungeImg, lounge);
		DragSource loungeDS = new DragSource();
		loungeDS.createDefaultDragGestureRecognizer(loungeImg, DnDConstants.ACTION_COPY, this);
		loungeImg.setBorder(BorderFactory.createLineBorder(Color.black));
		roomPaneCenter.add(loungeImg);
		
		roomPaneCenter.add(Box.createRigidArea(new Dimension(0, SPACEBETWROOM)));  
		
		
		Room hall=new Room("Hall");
		JLabel hallImg = new JLabel();
		hallImg.setIcon(hall.getScaledImage(SCALEROOM));
		hallImg.setToolTipText(hall.getName());
		allCard.put("Hall", hall);
		allLabel.put(hallImg, hall);
		DragSource hallDS = new DragSource();
		hallDS.createDefaultDragGestureRecognizer(hallImg, DnDConstants.ACTION_COPY, this);
		hallImg.setBorder(BorderFactory.createLineBorder(Color.black));
		roomPaneCenter.add(hallImg);

		roomPane.add(roomPaneCenter);

		
		JPanel roomPaneRight=new JPanel();
		 
		roomPaneRight.setLayout(new BoxLayout(roomPaneRight, BoxLayout.Y_AXIS));
		roomPaneRight.setBackground(Color.BLACK);
				
		Room conservatory=new Room("Conservatory");
		JLabel conservatoryImg = new JLabel();
		conservatoryImg.setIcon(conservatory.getScaledImage(SCALEROOM));
		conservatoryImg.setToolTipText(conservatory.getName());
		allCard.put("Conservatory", conservatory);
		allLabel.put(conservatoryImg, conservatory);
		DragSource conservatoryDS = new DragSource();
		conservatoryDS.createDefaultDragGestureRecognizer(conservatoryImg, DnDConstants.ACTION_COPY, this);
		conservatoryImg.setBorder(BorderFactory.createLineBorder(Color.black));
		roomPaneRight.add(conservatoryImg);
		
		roomPaneRight.add(Box.createRigidArea(new Dimension(0, SPACEBETWROOM)));
		
		Room library=new Room("Library");
		JLabel libraryImg = new JLabel();
		libraryImg.setIcon(library.getScaledImage(SCALEROOM));
		libraryImg.setToolTipText(library.getName());
		allCard.put("Library", library);
		allLabel.put(libraryImg, library);
		DragSource libraryDS = new DragSource();
		libraryDS.createDefaultDragGestureRecognizer(libraryImg, DnDConstants.ACTION_COPY, this);
		libraryImg.setBorder(BorderFactory.createLineBorder(Color.black));
		roomPaneRight.add(libraryImg);
		
		roomPaneRight.add(Box.createRigidArea(new Dimension(0, SPACEBETWROOM)));
		
		Room study=new Room("Study");
		JLabel studyImg = new JLabel();
		studyImg.setIcon(study.getScaledImage(SCALEROOM));
		studyImg.setToolTipText(study.getName());
		allCard.put("Study", study);
		allLabel.put(studyImg, study);
		DragSource studyDS = new DragSource();
		studyDS.createDefaultDragGestureRecognizer(studyImg, DnDConstants.ACTION_COPY, this);
		studyImg.setBorder(BorderFactory.createLineBorder(Color.black));
		roomPaneRight.add(studyImg);
				
		roomPane.add(roomPaneRight);
		
		JPanel allRoomPane=new JPanel();
		
		allRoomPane.add(roomPane);
		
		allRoomPane.setBackground(Color.BLACK);
		
		tabbedPane.addTab("STANZE",allRoomPane);
		
		allRoomPane.setName("STANZE");
		
		allRoomPane.setBorder(BorderFactory.createLineBorder(Color.GRAY));

		
		log.printLog("WestPanel: Tutte le carte sono state aggiunte sul tavolo");
		
		JLabel infoLabel = new JLabel("INFO");
		infoLabel.setForeground(Color.WHITE);
		infoLabel.setAlignmentX(CENTER_ALIGNMENT);
		infoLabel.setFont(new Font("Verdana", Font.ITALIC, 18));
		
		add(Box.createRigidArea(new Dimension(0,5)));
		
		info = new JTextPane();
		info.setEditable(false);
		info.setBackground(Color.LIGHT_GRAY);
		
		JPanel infoPane = new JPanel();
		
		infoPane.setBackground(Color.BLACK);
		
		infoPane.setLayout(new BoxLayout(infoPane, BoxLayout.X_AXIS));
		
		infoPane.add(Box.createRigidArea(new Dimension(15,0)));
		
		JScrollPane infoScrollPane = new JScrollPane(info);
		infoScrollPane.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
		infoScrollPane.setPreferredSize(new Dimension(80,150));
		
		infoScrollPane.setBorder(BorderFactory.createLineBorder(Color.WHITE,2));
		
		infoPane.add(infoScrollPane);
		
		infoPane.add(Box.createRigidArea(new Dimension(15,0)));
		
		tabbedPane.setForegroundAt(0, Color.WHITE);
		tabbedPane.addChangeListener(this);
		
		JPanel tabbedPaneContainer= new JPanel();
		
		tabbedPaneContainer.setBackground(Color.DARK_GRAY);
		
		tabbedPaneContainer.setLayout(new BoxLayout(tabbedPaneContainer, BoxLayout.Y_AXIS));
		
		tabbedPaneContainer.add(tabbedPane);
		
		tabbedPaneContainer.setBorder(BorderFactory.createLineBorder(Color.GRAY));
		
		JPanel keepTabbedWidth= new JPanel();
		
		keepTabbedWidth.setBackground(Color.BLACK);
		
		keepTabbedWidth.setLayout(new FlowLayout());
		
		keepTabbedWidth.add(tabbedPaneContainer);
		
		JPanel upPane = new JPanel();
		upPane.setBackground(Color.BLACK);
		
		upPane.setLayout(new BoxLayout(upPane, BoxLayout.Y_AXIS));
		
		upPane.add(Box.createRigidArea(new Dimension(0,5)));
		upPane.add(userPane);
		upPane.add(Box.createRigidArea(new Dimension(0,10)));
		upPane.add(keepTabbedWidth);
		upPane.add(Box.createRigidArea(new Dimension(0,SPACEBETWSECT)));
		downPane.add(infoLabel);
		downPane.add(Box.createRigidArea(new Dimension(0,5)));
		downPane.add(infoPane);
		downPane.add(Box.createRigidArea(new Dimension(0,15)));
		
		log.printLog("WestPanel: e' stata aggiunta l'area delle info");
		
		add(upPane,BorderLayout.PAGE_START);
		add(downPane,BorderLayout.CENTER);
		
		log.printLog("WestPanel: e' stato creato il pannello West");
		
	}
	
	
	/**
	 * Ottiene il JTabbedPane in cui sono rappresentate tutte le carte
	 * @return vedi descrizione metodo  
	 */
	
	public JTabbedPane getTabbedPane(){
		
		return tabbedPane;
	}
	
	
	/**
	 * Restituisce l'aea delle informazioni
	 * @return vedi descrizione metodo
	 */
	public JTextPane getInfoArea(){
		
		return info;
		
	}
	
	
	/**
	 * Controlla se la carta passata e' segnata come scartata nel pannello contenente le carte
	 * @return true se risulta scartata, false altrimenti
	 */
	public boolean isDiscardedCard(Card card){
		
		String cardName= card.getName();
		
		if(allCard.containsKey(cardName)){
		
			if(allCard.get(cardName).isDeleted()) return true;
							
		}
		
		return false;
		
	}
	
	
	/** Imposta graficamente la carta come non corretta ai fini dell'ipotesi/soluzione
	 *  @param card carta da escludere
	 */
	public void discardCard(Card card){
		
		String cardName= card.getName();
		
		if(allCard.containsKey(cardName)){
			
			ImageIcon deletedIm = allCard.get(cardName).delCard();
			
			if(deletedIm==null) return; //carta gia' stata eliminata
			
			log.print("WestPanel: e' stata eliminata dalla soluzione la carta ["+cardName+"]");
			
			for (Map.Entry<JLabel, Card> entry : allLabel.entrySet()){
			
				if(entry.getValue().equals(card))
					entry.getKey().setIcon(deletedIm);
				
			}
			
		}
		
	}
	
	/**
	 * Inizia l'azione di drag delle carte dal tabellone alla finestra di formulazione ipotesi/soluzione
	 */
	 @Override
	 public void dragGestureRecognized(DragGestureEvent event) {
		 	
		 	Card tmpCard = null;
		    Cursor cursor = null;
		    JLabel imgLab = (JLabel) event.getComponent();
		    ImageIcon imgCard=null;
		    boolean isWeap=false;
		    boolean isCh=false;
		    
		    if(allLabel.containsKey(imgLab)){
		    	
		    	tmpCard = allLabel.get(imgLab);
		    	if(tmpCard.isDeleted())
		    		imgCard= (ImageIcon) tmpCard.getDeletedCardImage();
		    	else
		    		imgCard= (ImageIcon) tmpCard.getImage();
		    	if(tmpCard instanceof Weapon)
		    		isWeap=true;
		    	else if(tmpCard instanceof Character)
		    		isCh=true;
		    	
		    } else log.printErr("WestPanel: Drag non previsto");
		    
	  		
		    
		    if (event.getDragAction() == DnDConstants.ACTION_COPY) {
		      cursor = DragSource.DefaultCopyDrop;
		    }
		    
		     event.startDrag(cursor,new TransferableCard(imgCard));
		     
		     if(isWeap){ //weapon
		    	 wind.isWeapDragged=true;
		    	 wind.isChDragged=false;
		    	 wind.draggedWeap = (Weapon) tmpCard;
		     }
		     else if (isCh){ //character
		    	 wind.isWeapDragged=false;
		    	 wind.isChDragged=true;
		    	 wind.draggedCh = (Character) tmpCard; 
		     }
		     else{ //room
		    	 wind.isWeapDragged=false;
		    	 wind.isChDragged=false;
		    	 wind.draggedRoom= (Room) tmpCard;
		    	 
		     }
		  }

	 
		public void actionPerformed(ActionEvent e) {	//click sui tasti (esci o soluzione)
	        
			if (e.getActionCommand().compareTo("Quit")==0){ // btnQuit
				// bottone "Esci da Cluedo"
				
				wind.mainWindowClosing();
					
			}
			
		}


		@Override
		public void stateChanged(ChangeEvent e) {
			Component c = tabbedPane.getSelectedComponent();
			
			if(c.getName().equals("ARMI")){
				tabbedPane.setForegroundAt(0, Color.GRAY);
				tabbedPane.setForegroundAt(1, Color.WHITE);
				tabbedPane.setForegroundAt(2, Color.GRAY);
			}
			else if(c.getName().equals("PERSONAGGI")){
				tabbedPane.setForegroundAt(0, Color.WHITE);
				tabbedPane.setForegroundAt(1, Color.GRAY);
				tabbedPane.setForegroundAt(2, Color.GRAY);
			}
			if(c.getName().equals("STANZE")){
				tabbedPane.setForegroundAt(0, Color.GRAY);
				tabbedPane.setForegroundAt(1, Color.GRAY);
				tabbedPane.setForegroundAt(2, Color.WHITE);
			}
		}


		@Override
		public void mouseDragged(MouseEvent e) {
			
		}


		@Override
		public void mouseMoved(MouseEvent e) {
			
			if(e.getSource()==tabbedPane){
				
				JTabbedPane tp = (JTabbedPane) e.getSource();
				int ix = tp.indexAtLocation( e.getX(), e.getY() );

				if ( ix == 0 || ix==1 || ix==2 ){
					
					tabbedPane.setCursor(new Cursor(Cursor.HAND_CURSOR));
				}

				if ( ix == -1 ){
					tabbedPane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
					
				}				
			}
			
		}
	 
	
}


